<?php
/* @var $this ProfessionController */
/* @var $model Profession */
?>
<script type="text/javascript">
function rate(score){
	
if('<?php echo Yii::app()->user->isGuest?>'){
	alert('<?php echo  Yii::t('default','must.login'); ?>');
	return false;
}else{
	var xmlhttp;
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
	    {
	   // document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
	    }
	  }
	xmlhttp.open("GET",'<?php echo CController::createUrl('/profession/ajaxRate?score=');?>'+score+'&professionId=<?php echo $model->id ?>',true);
	xmlhttp.send();
}
		
}

function goLogin(){
	location.href="<?php echo  Yii::app()->getBaseUrl(true) ;?>/site/login";
}


function deleteComment(commentId){
	if(confirm('<?php echo Yii::t('profession_messages','delete.confirm'); ?>')){ 
			location.href="<?php echo  Yii::app()->getBaseUrl(true) ;?>/profession/deleteComment?commentId="+commentId+"&professionId=<?php echo $model->id?>";
		}
}


</script>
<style type="text/css">

	table 
		{
		width:100%;
		}
	th
		{
		height:50px;
		}     
	 td
		{
		text-align: <?php if(Yii::app()->language == 'ar')  echo "right"; else echo "left"; ?>;
		}
	
</style>    

<style type="text/css">
	.labels {
	   color: red;
	   background-color: white;
	   font-family: "Lucida Grande", "Arial", sans-serif;
	   font-size: 10px;
	   font-weight: bold;
	   text-align: center;
	   width: 40px;     
	   border: 2px solid black;
	   white-space: nowrap;
	}
	</style>
	
<?php
$this->breadcrumbs=array(
	Yii::t('default','Professions') =>array('index'),
	Yii::t('profession_messages','profession.view'),
);

if(!Yii::app()->user->isGuest){
$this->menu=array(
	array('label'=>Yii::t('profession_messages','profession.viewAll'), 'url'=>array('index')),
	array('label'=>Yii::t('profession_messages','profession.create'), 'url'=>array('create')),
	array('label'=>Yii::t('profession_messages','profession.manage'), 'url'=>array('admin')),
);
}
?>

<h1><?php echo Yii::t('profession_messages','profession.view'); ?></h1>
<br/><br/>
<table>
<tr><td colspan="2">
<?php /*
$this->widget('ext.DzRaty.DzRaty', array(
		'name' => 'my_rating_field',
		'value' => 3,
		'options' => array(
				'readOnly' => TRUE,
		),
));
*/
?>
</td></tr>
	<tr><td style="width:20%">
	<b><?php echo CHtml::encode($model->getAttributeLabel('name')); ?>:</b>
	</td><td>
	<?php echo CHtml::encode($model->name); ?>
	<br />
	</td></tr>
	
	<tr><td style="width:20%">
	<b><?php echo CHtml::encode($model->getAttributeLabel('description')); ?>:</b>
	</td><td>
	<?php echo CHtml::encode($model->description); ?>
	<br />
	</td></tr>
	
	<tr><td style="width:20%">
	<b><?php echo CHtml::encode($model->getAttributeLabel('mobile')); ?>:</b>
	</td><td>
	<?php echo CHtml::encode($model->mobile); ?>
	<br />
	</td></tr>
	
	<tr><td style="width:20%">
	<b><?php echo CHtml::encode($model->getAttributeLabel('email')); ?>:</b>
	</td><td>
	<?php echo CHtml::encode($model->email); ?>
	<br />
	</td></tr>
	
	<tr><td style="width:20%">
	<b><?php echo CHtml::encode($model->getAttributeLabel('professionType_id')); ?>:</b>
	</td><td>
	<?php echo CHtml::encode($model->professionTypeString); ?>
	<br />
	</td></tr>
	
	<tr><td style="width:20%">
	<b><?php echo CHtml::encode($model->getAttributeLabel('state_id')); ?>:</b>
	</td><td>
	<?php echo CHtml::encode($model->stateString); ?>
	<br />
	</td></tr>
	
	<tr><td style="width:20%">
	<b><?php echo CHtml::encode($model->getAttributeLabel('region_id')); ?>:</b>
	</td><td>
	<?php echo CHtml::encode($model->regionString); ?>
	<br />
	</td></tr>
	
	<tr><td colspan="2">
	<table style="width:50%;font-size: 10px"><tr><td  style="width:35%">
	<b><?php echo CHtml::encode($model->getAttributeLabel('created_by')); ?>:</b>
	</td><td>
	<a href="#"><?php echo CHtml::encode($model->createdBy->username); ?></a>
	</td></tr></table>
	</td><td>
	<br />
	</td></tr>
	
	<?php if(!Yii::app()->user->isGuest){ ?>
		<tr><td colspan="2">
		<?php
		   $this->widget('dzRaty.DzRaty', array(
			'name' => 'my_rating_field2',
			'value' => $model->getUserRate(),
			'options' => array(
			'click' => "js:function(score, evt){ rate(score); }",
			'width' => 200,
			'cancel' => TRUE,
			'cancelPlace' => 'right',
				),
			));
			
			?>   
		
		</td></tr>
	<?php } ?>	
	
	<?php if($model->lat != null && $model->long != null){ ?>
	<tr><td><br/></td></tr>
	<tr><td colspan="2">
	
	<?php 
	Yii::import('EGMap.*');
	$gMap = new EGMap();
	$gMap->zoom = 17;
	$mapTypeControlOptions = array(
			'position'=> EGMapControlPosition::TOP_RIGHT,
			'style'=>EGMap::TYPE_SATELLITE
	);
	
	$gMap->mapTypeControlOptions= $mapTypeControlOptions;
	
	$gMap->setCenter($model->lat, $model->long);
	
	$info_window_b = new EGMapInfoWindow($model->description);
	
	// Create marker with label
	$marker = new EGMapMarkerWithLabel($model->lat,$model->long, array('title' => $model->description));
	
	$label_options = array(
			'backgroundColor'=>'yellow',
			'opacity'=>'0.75',
			'width'=>'100px',
			'color'=>'blue'
	);
	
	
	// SECOND WAY:
	$marker->labelContent= $model->name;
	$marker->labelStyle=$label_options;
	$marker->draggable=false;
	$marker->labelClass='labels';
	$marker->raiseOnDrag= true;
	
	$marker->setLabelAnchor(new EGMapPoint(22,0));
	
	$marker->addHtmlInfoWindow($info_window_b);
	
	$gMap->addMarker($marker);
	
	// enabling marker clusterer just for fun
	// to view it zoom-out the map
	$gMap->enableMarkerClusterer(new EGMapMarkerClusterer());
	
	$gMap->renderMap();
?>
	
	</td></tr>
	<?php } ?>
	<?php if(Yii::app()->user->isGuest){ ?>
	<tr><td colspan="2"><div class="comment">
			<?php Yii::app()->user->setState('__returnUrl',Yii::app()->request->getUrl()); ?>
			<?php echo  Yii::t('default','must.login'); ?><br/><br/>
			<p><?php echo TbHtml::button(Yii::t('default','Login'),array('color' => TbHtml::BUTTON_COLOR_PRIMARY, 'size' => TbHtml::BUTTON_SIZE_SMALL,'onclick'=>'goLogin();')); ?></p>
	</div></td></tr>
	<?php } ?>
</table>

<div id="comments">
	<?php if($model->commentCount>=1): ?>
		<h5>
			<?php echo $model->commentCount>1 ? $model->commentCount .' '. Yii::t('profession_messages','profession.comments') : Yii::t('profession_messages','profession.one.comment'); ?>
		</h5>

		<?php $this->renderPartial('_comments',array(
			'profession'=>$model,
			'comments'=>$model->comments,
		)); ?>
	<?php endif; ?>
<br/>
	
	<?php
		if(!Yii::app()->user->isGuest){
			 $this->renderPartial('/comment/_form',array(
				'model'=>$comment,
			)); 	
		}
	?>
		
		
</div><!-- comments -->
